﻿#include "Server.MagicInfoForm.h"
#include "../Server.SMain.h"
#include "../../Shared/Data/ItemData.h"

using namespace Server::MirDatabase;
using namespace Server::MirEnvir;

namespace Server
{

    Server::MirEnvir::Envir *MagicInfoForm::getEnvir() const
    {
        return SMain::getEditEnvir();
    }

    MagicInfoForm::MagicInfoForm()
    {
        InitializeComponent();
        for (int i = 0; i < getEnvir()->MagicInfoList.size(); i++)
        {
            MagiclistBox->Items->Add(getEnvir()->MagicInfoList[i]);
        }
        UpdateMagicForm();
    }

    void MagicInfoForm::UpdateMagicForm(unsigned char field)
    {
         _selectedMagicInfo = static_cast<MagicInfo*>(MagiclistBox->SelectedItem);

         lblBookValid->BackColor = SystemColors::Window;

         if (_selectedMagicInfo == nullptr)
         {
             tabControl1->Enabled = false;
             lblBookValid->Text = "Searching";
             lblSelected->Text = "Selected Skill: none";
             lblDamageExample->Text = "";
             lblDamageExplained->Text = "";
             txtSkillIcon->Text = "0";
             txtSkillLvl1Points->Text = "0";
             txtSkillLvl1Req->Text = "0";
             txtSkillLvl2Points->Text = "0";
             txtSkillLvl2Req->Text = "0";
             txtSkillLvl3Points->Text = "0";
             txtSkillLvl3Req->Text = "0";
             txtMPBase->Text = "0";
             txtMPIncrease->Text = "0";
             txtDelayBase->Text = "0";
             txtDelayReduction->Text = "0";
             txtDmgBaseMin->Text = "0";
             txtDmgBaseMax->Text = "0";
             txtDmgBonusMin->Text = "0";
             txtDmgBonusMax->Text = "0";
         }
         else
         {
             tabControl1->Enabled = true;
//C# TO C++ CONVERTER TODO TASK: There is no C++ equivalent to 'ToString':
             lblSelected->Text = "Selected Skill: " + _selectedMagicInfo->ToString();
             lblDamageExample->Text = std::string::Format("Damage @ Skill level 0: {0:000}-{1:000}   |||   level 1: {2:000}-{3:000}   |||   level 2: {4:000}-{5:000}   |||   level 3: {6:000}-{7:000}", GetMinPower(0), GetMaxPower(0), GetMinPower(1), GetMaxPower(1), GetMinPower(2), GetMaxPower(2), GetMinPower(3), GetMaxPower(3));
             lblDamageExplained->Text = std::string::Format("Damage: {{Random(minstat-maxstat) + [<(random({0}-{1})/4) X (skill level +1)> + random<{2}-{3}>]}}  X  {{{4} + (skill level * {5})}}", _selectedMagicInfo->MPowerBase, _selectedMagicInfo->MPowerBase + _selectedMagicInfo->MPowerBonus, _selectedMagicInfo->PowerBase, _selectedMagicInfo->PowerBonus + _selectedMagicInfo->PowerBase, _selectedMagicInfo->MultiplierBase, _selectedMagicInfo->MultiplierBonus);
             txtSkillIcon->Text = std::to_string(_selectedMagicInfo->Icon);
             txtSkillLvl1Points->Text = std::to_string(_selectedMagicInfo->Need1);
             txtSkillLvl1Req->Text = std::to_string(_selectedMagicInfo->Level1);
             txtSkillLvl2Points->Text = std::to_string(_selectedMagicInfo->Need2);
             txtSkillLvl2Req->Text = std::to_string(_selectedMagicInfo->Level2);
             txtSkillLvl3Points->Text = std::to_string(_selectedMagicInfo->Need3);
             txtSkillLvl3Req->Text = std::to_string(_selectedMagicInfo->Level3);
             txtMPBase->Text = std::to_string(_selectedMagicInfo->BaseCost);
             txtMPIncrease->Text = std::to_string(_selectedMagicInfo->LevelCost);
             txtDelayBase->Text = std::to_string(_selectedMagicInfo->DelayBase);
             txtDelayReduction->Text = std::to_string(_selectedMagicInfo->DelayReduction);
             txtDmgBaseMin->Text = std::to_string(_selectedMagicInfo->PowerBase);
             txtDmgBaseMax->Text = std::to_string(_selectedMagicInfo->PowerBase + _selectedMagicInfo->PowerBonus);
             txtDmgBonusMin->Text = std::to_string(_selectedMagicInfo->MPowerBase);
             txtDmgBonusMax->Text = std::to_string(_selectedMagicInfo->MPowerBase + _selectedMagicInfo->MPowerBonus);
             if (field != 1)
             {
                txtDmgMultBase->Text = std::to_string(_selectedMagicInfo->MultiplierBase);
             }
             if (field != 2)
             {
             txtDmgMultBoost->Text = std::to_string(_selectedMagicInfo->MultiplierBonus);
             }
             txtRange->Text = std::to_string(_selectedMagicInfo->Range);
             ItemInfo *Book = getEnvir()->GetBook(static_cast<short>(_selectedMagicInfo->Spell));
             if (Book != nullptr)
             {
                 lblBookValid->Text = Book->Name;
             }
             else
             {
                 lblBookValid->Text = "No book found";
                 lblBookValid->BackColor = Color::Red;
             }
            this->textBoxName->Text = _selectedMagicInfo->Name;
         }
    }

    int MagicInfoForm::GetMaxPower(unsigned char level)
    {
        if (_selectedMagicInfo == nullptr)
        {
            return 0;
        }
        return static_cast<int>(BankersRounding::round((((_selectedMagicInfo->MPowerBase + _selectedMagicInfo->MPowerBonus) / 4.0F) * (level + 1) + (_selectedMagicInfo->PowerBase + _selectedMagicInfo->PowerBonus)) * (_selectedMagicInfo->MultiplierBase + (level * _selectedMagicInfo->MultiplierBonus))));
    }

    int MagicInfoForm::GetMinPower(unsigned char level)
    {
        if (_selectedMagicInfo == nullptr)
        {
            return 0;
        }
        return static_cast<int>(BankersRounding::round(((_selectedMagicInfo->MPowerBase / 4.0F) * (level + 1) + _selectedMagicInfo->PowerBase) * (_selectedMagicInfo->MultiplierBase + (level * _selectedMagicInfo->MultiplierBonus))));
    }

    void MagicInfoForm::InitializeComponent()
    {
        this->components = new System::ComponentModel::Container();
        this->MagiclistBox = new System::Windows::Forms::ListBox();
        this->tabControl1 = new System::Windows::Forms::TabControl();
        this->tabPage1 = new System::Windows::Forms::TabPage();
        this->lblDamageExample = new System::Windows::Forms::Label();
        this->lblDamageExplained = new System::Windows::Forms::Label();
        this->lblSelected = new System::Windows::Forms::Label();
        this->panel4 = new System::Windows::Forms::Panel();
        this->txtDmgMultBoost = new System::Windows::Forms::TextBox();
        this->txtDmgMultBase = new System::Windows::Forms::TextBox();
        this->label21 = new System::Windows::Forms::Label();
        this->label22 = new System::Windows::Forms::Label();
        this->txtDmgBonusMax = new System::Windows::Forms::TextBox();
        this->txtDmgBonusMin = new System::Windows::Forms::TextBox();
        this->label18 = new System::Windows::Forms::Label();
        this->label19 = new System::Windows::Forms::Label();
        this->txtDmgBaseMax = new System::Windows::Forms::TextBox();
        this->txtDmgBaseMin = new System::Windows::Forms::TextBox();
        this->label17 = new System::Windows::Forms::Label();
        this->label16 = new System::Windows::Forms::Label();
        this->label15 = new System::Windows::Forms::Label();
        this->panel3 = new System::Windows::Forms::Panel();
        this->label20 = new System::Windows::Forms::Label();
        this->txtRange = new System::Windows::Forms::TextBox();
        this->txtDelayReduction = new System::Windows::Forms::TextBox();
        this->txtDelayBase = new System::Windows::Forms::TextBox();
        this->label14 = new System::Windows::Forms::Label();
        this->label13 = new System::Windows::Forms::Label();
        this->label12 = new System::Windows::Forms::Label();
        this->panel2 = new System::Windows::Forms::Panel();
        this->txtMPIncrease = new System::Windows::Forms::TextBox();
        this->txtMPBase = new System::Windows::Forms::TextBox();
        this->label11 = new System::Windows::Forms::Label();
        this->label10 = new System::Windows::Forms::Label();
        this->label9 = new System::Windows::Forms::Label();
        this->panel1 = new System::Windows::Forms::Panel();
        this->txtSkillLvl3Points = new System::Windows::Forms::TextBox();
        this->txtSkillLvl2Points = new System::Windows::Forms::TextBox();
        this->txtSkillLvl1Points = new System::Windows::Forms::TextBox();
        this->label6 = new System::Windows::Forms::Label();
        this->label7 = new System::Windows::Forms::Label();
        this->label8 = new System::Windows::Forms::Label();
        this->txtSkillLvl3Req = new System::Windows::Forms::TextBox();
        this->txtSkillLvl2Req = new System::Windows::Forms::TextBox();
        this->txtSkillLvl1Req = new System::Windows::Forms::TextBox();
        this->label5 = new System::Windows::Forms::Label();
        this->label4 = new System::Windows::Forms::Label();
        this->label3 = new System::Windows::Forms::Label();
        this->label2 = new System::Windows::Forms::Label();
        this->txtSkillIcon = new System::Windows::Forms::TextBox();
        this->label1 = new System::Windows::Forms::Label();
        this->lblBookValid = new System::Windows::Forms::Label();
        this->toolTip1 = new System::Windows::Forms::ToolTip(this->components);
        this->textBoxName = new System::Windows::Forms::TextBox();
        this->label23 = new System::Windows::Forms::Label();
        this->label24 = new System::Windows::Forms::Label();
        this->tabControl1->SuspendLayout();
        this->tabPage1->SuspendLayout();
        this->panel4->SuspendLayout();
        this->panel3->SuspendLayout();
        this->panel2->SuspendLayout();
        this->panel1->SuspendLayout();
        this->SuspendLayout();
        // 
        // MagiclistBox
        // 
        this->MagiclistBox->Dock = System::Windows::Forms::DockStyle::Left;
        this->MagiclistBox->FormattingEnabled = true;
        this->MagiclistBox->ItemHeight = 12;
        this->MagiclistBox->Location = new System::Drawing::Point(0, 0);
        this->MagiclistBox->Name = "MagiclistBox";
        this->MagiclistBox->Size = new System::Drawing::Size(225, 542);
        this->MagiclistBox->TabIndex = 0;
        this->MagiclistBox->SelectedIndexChanged += new System::EventHandler(this->MagiclistBox_SelectedIndexChanged);
        // 
        // tabControl1
        // 
        this->tabControl1->Controls->Add(this->tabPage1);
        this->tabControl1->Dock = System::Windows::Forms::DockStyle::Fill;
        this->tabControl1->Location = new System::Drawing::Point(225, 0);
        this->tabControl1->Name = "tabControl1";
        this->tabControl1->SelectedIndex = 0;
        this->tabControl1->Size = new System::Drawing::Size(702, 542);
        this->tabControl1->TabIndex = 1;
        // 
        // tabPage1
        // 
        this->tabPage1->Controls->Add(this->label24);
        this->tabPage1->Controls->Add(this->label23);
        this->tabPage1->Controls->Add(this->textBoxName);
        this->tabPage1->Controls->Add(this->lblDamageExample);
        this->tabPage1->Controls->Add(this->lblDamageExplained);
        this->tabPage1->Controls->Add(this->lblSelected);
        this->tabPage1->Controls->Add(this->panel4);
        this->tabPage1->Controls->Add(this->panel3);
        this->tabPage1->Controls->Add(this->panel2);
        this->tabPage1->Controls->Add(this->panel1);
        this->tabPage1->Controls->Add(this->txtSkillIcon);
        this->tabPage1->Controls->Add(this->label1);
        this->tabPage1->Controls->Add(this->lblBookValid);
        this->tabPage1->Location = new System::Drawing::Point(4, 22);
        this->tabPage1->Name = "tabPage1";
        this->tabPage1->Padding = new System::Windows::Forms::Padding(3);
        this->tabPage1->Size = new System::Drawing::Size(694, 516);
        this->tabPage1->TabIndex = 0;
        this->tabPage1->Text = "Basics";
        this->tabPage1->UseVisualStyleBackColor = true;
        // 
        // lblDamageExample
        // 
        this->lblDamageExample->AutoSize = true;
        this->lblDamageExample->Location = new System::Drawing::Point(11, 394);
        this->lblDamageExample->Name = "lblDamageExample";
        this->lblDamageExample->Size = new System::Drawing::Size(89, 12);
        this->lblDamageExample->TabIndex = 0;
        this->lblDamageExample->Text = "Damage example";
        // 
        // lblDamageExplained
        // 
        this->lblDamageExplained->AutoSize = true;
        this->lblDamageExplained->Location = new System::Drawing::Point(11, 366);
        this->lblDamageExplained->Name = "lblDamageExplained";
        this->lblDamageExplained->Size = new System::Drawing::Size(47, 12);
        this->lblDamageExplained->TabIndex = 9;
        this->lblDamageExplained->Text = "Damage:";
        // 
        // lblSelected
        // 
        this->lblSelected->AutoSize = true;
        this->lblSelected->Location = new System::Drawing::Point(20, 3);
        this->lblSelected->Name = "lblSelected";
        this->lblSelected->Size = new System::Drawing::Size(101, 12);
        this->lblSelected->TabIndex = 8;
        this->lblSelected->Text = "Selected skill: ";
        // 
        // panel4
        // 
        this->panel4->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
        this->panel4->Controls->Add(this->txtDmgMultBoost);
        this->panel4->Controls->Add(this->txtDmgMultBase);
        this->panel4->Controls->Add(this->label21);
        this->panel4->Controls->Add(this->label22);
        this->panel4->Controls->Add(this->txtDmgBonusMax);
        this->panel4->Controls->Add(this->txtDmgBonusMin);
        this->panel4->Controls->Add(this->label18);
        this->panel4->Controls->Add(this->label19);
        this->panel4->Controls->Add(this->txtDmgBaseMax);
        this->panel4->Controls->Add(this->txtDmgBaseMin);
        this->panel4->Controls->Add(this->label17);
        this->panel4->Controls->Add(this->label16);
        this->panel4->Controls->Add(this->label15);
        this->panel4->Location = new System::Drawing::Point(14, 166);
        this->panel4->Name = "panel4";
        this->panel4->Size = new System::Drawing::Size(233, 191);
        this->panel4->TabIndex = 6;
        // 
        // txtDmgMultBoost
        // 
        this->txtDmgMultBoost->Location = new System::Drawing::Point(168, 157);
        this->txtDmgMultBoost->Name = "txtDmgMultBoost";
        this->txtDmgMultBoost->Size = new System::Drawing::Size(46, 21);
        this->txtDmgMultBoost->TabIndex = 14;
        this->toolTip1->SetToolTip(this->txtDmgMultBoost, "extra multiplyer apply\'d for every skill level");
        this->txtDmgMultBoost->TextChanged += new System::EventHandler(this->txtDmgMultBoost_TextChanged);
        // 
        // txtDmgMultBase
        // 
        this->txtDmgMultBase->Location = new System::Drawing::Point(168, 131);
        this->txtDmgMultBase->Name = "txtDmgMultBase";
        this->txtDmgMultBase->Size = new System::Drawing::Size(46, 21);
        this->txtDmgMultBase->TabIndex = 13;
        this->toolTip1->SetToolTip(this->txtDmgMultBase, "multiplier apply\'d to total skill dmg");
        this->txtDmgMultBase->TextChanged += new System::EventHandler(this->txtDmgMultBase_TextChanged);
        // 
        // label21
        // 
        this->label21->AutoSize = true;
        this->label21->Location = new System::Drawing::Point(12, 160);
        this->label21->Name = "label21";
        this->label21->Size = new System::Drawing::Size(197, 12);
        this->label21->TabIndex = 12;
        this->label21->Text = "Damage multiplyer boost/skilllvl";
        // 
        // label22
        // 
        this->label22->AutoSize = true;
        this->label22->Location = new System::Drawing::Point(12, 134);
        this->label22->Name = "label22";
        this->label22->Size = new System::Drawing::Size(137, 12);
        this->label22->TabIndex = 11;
        this->label22->Text = "Damage multiplyer base";
        // 
        // txtDmgBonusMax
        // 
        this->txtDmgBonusMax->Location = new System::Drawing::Point(168, 105);
        this->txtDmgBonusMax->Name = "txtDmgBonusMax";
        this->txtDmgBonusMax->Size = new System::Drawing::Size(46, 21);
        this->txtDmgBonusMax->TabIndex = 10;
        this->toolTip1->SetToolTip(this->txtDmgBonusMax, "Damage bonus at skill level \'4\' ");
        this->txtDmgBonusMax->TextChanged += new System::EventHandler(this->txtDmgBonusMax_TextChanged);
        // 
        // txtDmgBonusMin
        // 
        this->txtDmgBonusMin->Location = new System::Drawing::Point(168, 79);
        this->txtDmgBonusMin->Name = "txtDmgBonusMin";
        this->txtDmgBonusMin->Size = new System::Drawing::Size(46, 21);
        this->txtDmgBonusMin->TabIndex = 9;
        this->toolTip1->SetToolTip(this->txtDmgBonusMin, "Damage bonus at skill level \'4\' \r\nyou will get 1/4th of this bonus for every skil" + "l level\r\nnote ingame level 0 = 1 bonus, so level 3 = max bonus (4)");
        this->txtDmgBonusMin->TextChanged += new System::EventHandler(this->txtDmgBonusMin_TextChanged);
        // 
        // label18
        // 
        this->label18->AutoSize = true;
        this->label18->Location = new System::Drawing::Point(12, 108);
        this->label18->Name = "label18";
        this->label18->Size = new System::Drawing::Size(161, 12);
        this->label18->TabIndex = 8;
        this->label18->Text = "Maximum skill lvl 3 damage";
        // 
        // label19
        // 
        this->label19->AutoSize = true;
        this->label19->Location = new System::Drawing::Point(12, 82);
        this->label19->Name = "label19";
        this->label19->Size = new System::Drawing::Size(167, 12);
        this->label19->TabIndex = 7;
        this->label19->Text = "Minimum skill lvl 3 damage:";
        // 
        // txtDmgBaseMax
        // 
        this->txtDmgBaseMax->Location = new System::Drawing::Point(168, 53);
        this->txtDmgBaseMax->Name = "txtDmgBaseMax";
        this->txtDmgBaseMax->Size = new System::Drawing::Size(46, 21);
        this->txtDmgBaseMax->TabIndex = 6;
        this->toolTip1->SetToolTip(this->txtDmgBaseMax, "Damage at skill level 0");
        this->txtDmgBaseMax->TextChanged += new System::EventHandler(this->txtDmgBaseMax_TextChanged);
        // 
        // txtDmgBaseMin
        // 
        this->txtDmgBaseMin->Location = new System::Drawing::Point(168, 27);
        this->txtDmgBaseMin->Name = "txtDmgBaseMin";
        this->txtDmgBaseMin->Size = new System::Drawing::Size(46, 21);
        this->txtDmgBaseMin->TabIndex = 5;
        this->toolTip1->SetToolTip(this->txtDmgBaseMin, "Damage at skill level 0");
        this->txtDmgBaseMin->TextChanged += new System::EventHandler(this->txtDmgBaseMin_TextChanged);
        // 
        // label17
        // 
        this->label17->AutoSize = true;
        this->label17->Location = new System::Drawing::Point(12, 56);
        this->label17->Name = "label17";
        this->label17->Size = new System::Drawing::Size(119, 12);
        this->label17->TabIndex = 2;
        this->label17->Text = "Maximum base damage";
        // 
        // label16
        // 
        this->label16->AutoSize = true;
        this->label16->Location = new System::Drawing::Point(12, 30);
        this->label16->Name = "label16";
        this->label16->Size = new System::Drawing::Size(125, 12);
        this->label16->TabIndex = 1;
        this->label16->Text = "Minimum base damage:";
        // 
        // label15
        // 
        this->label15->AutoSize = true;
        this->label15->Location = new System::Drawing::Point(5, 8);
        this->label15->Name = "label15";
        this->label15->Size = new System::Drawing::Size(95, 12);
        this->label15->TabIndex = 0;
        this->label15->Text = "Damage settings";
        // 
        // panel3
        // 
        this->panel3->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
        this->panel3->Controls->Add(this->label20);
        this->panel3->Controls->Add(this->txtRange);
        this->panel3->Controls->Add(this->txtDelayReduction);
        this->panel3->Controls->Add(this->txtDelayBase);
        this->panel3->Controls->Add(this->label14);
        this->panel3->Controls->Add(this->label13);
        this->panel3->Controls->Add(this->label12);
        this->panel3->Location = new System::Drawing::Point(253, 166);
        this->panel3->Name = "panel3";
        this->panel3->Size = new System::Drawing::Size(216, 191);
        this->panel3->TabIndex = 5;
        this->toolTip1->SetToolTip(this->panel3, "delay = <base delay> - (skill level * <decrease>)");
        // 
        // label20
        // 
        this->label20->AutoSize = true;
        this->label20->Location = new System::Drawing::Point(12, 77);
        this->label20->Name = "label20";
        this->label20->Size = new System::Drawing::Size(113, 12);
        this->label20->TabIndex = 15;
        this->label20->Text = "Range (0 No limit)";
        // 
        // txtRange
        // 
        this->txtRange->Location = new System::Drawing::Point(121, 74);
        this->txtRange->Name = "txtRange";
        this->txtRange->Size = new System::Drawing::Size(79, 21);
        this->txtRange->TabIndex = 14;
        this->txtRange->TextChanged += new System::EventHandler(this->txtRange_TextChanged);
        // 
        // txtDelayReduction
        // 
        this->txtDelayReduction->Location = new System::Drawing::Point(121, 47);
        this->txtDelayReduction->Name = "txtDelayReduction";
        this->txtDelayReduction->Size = new System::Drawing::Size(79, 21);
        this->txtDelayReduction->TabIndex = 13;
        this->toolTip1->SetToolTip(this->txtDelayReduction, "delay = <base delay> - (skill level * <decrease>)");
        this->txtDelayReduction->TextChanged += new System::EventHandler(this->txtDelayReduction_TextChanged);
        // 
        // txtDelayBase
        // 
        this->txtDelayBase->Location = new System::Drawing::Point(121, 22);
        this->txtDelayBase->Name = "txtDelayBase";
        this->txtDelayBase->Size = new System::Drawing::Size(79, 21);
        this->txtDelayBase->TabIndex = 12;
        this->toolTip1->SetToolTip(this->txtDelayBase, "delay = <base delay> - (skill level * <decrease>)");
        this->txtDelayBase->TextChanged += new System::EventHandler(this->txtDelayBase_TextChanged);
        // 
        // label14
        // 
        this->label14->AutoSize = true;
        this->label14->Location = new System::Drawing::Point(12, 50);
        this->label14->Name = "label14";
        this->label14->Size = new System::Drawing::Size(137, 12);
        this->label14->TabIndex = 2;
        this->label14->Text = "Decrease / skill level";
        // 
        // label13
        // 
        this->label13->AutoSize = true;
        this->label13->Location = new System::Drawing::Point(12, 25);
        this->label13->Name = "label13";
        this->label13->Size = new System::Drawing::Size(65, 12);
        this->label13->TabIndex = 1;
        this->label13->Text = "Base delay";
        // 
        // label12
        // 
        this->label12->AutoSize = true;
        this->label12->Location = new System::Drawing::Point(12, 8);
        this->label12->Name = "label12";
        this->label12->Size = new System::Drawing::Size(149, 12);
        this->label12->TabIndex = 0;
        this->label12->Text = "Delay (in milliseconds!)";
        // 
        // panel2
        // 
        this->panel2->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
        this->panel2->Controls->Add(this->txtMPIncrease);
        this->panel2->Controls->Add(this->txtMPBase);
        this->panel2->Controls->Add(this->label11);
        this->panel2->Controls->Add(this->label10);
        this->panel2->Controls->Add(this->label9);
        this->panel2->Location = new System::Drawing::Point(253, 53);
        this->panel2->Name = "panel2";
        this->panel2->Size = new System::Drawing::Size(216, 107);
        this->panel2->TabIndex = 4;
        // 
        // txtMPIncrease
        // 
        this->txtMPIncrease->Location = new System::Drawing::Point(135, 47);
        this->txtMPIncrease->Name = "txtMPIncrease";
        this->txtMPIncrease->Size = new System::Drawing::Size(46, 21);
        this->txtMPIncrease->TabIndex = 12;
        this->toolTip1->SetToolTip(this->txtMPIncrease, "extra amount of mp used each level");
        this->txtMPIncrease->TextChanged += new System::EventHandler(this->txtMPIncrease_TextChanged);
        // 
        // txtMPBase
        // 
        this->txtMPBase->Location = new System::Drawing::Point(135, 22);
        this->txtMPBase->Name = "txtMPBase";
        this->txtMPBase->Size = new System::Drawing::Size(46, 21);
        this->txtMPBase->TabIndex = 11;
        this->toolTip1->SetToolTip(this->txtMPBase, "Mp usage when skill is level 0");
        this->txtMPBase->TextChanged += new System::EventHandler(this->txtMPBase_TextChanged);
        // 
        // label11
        // 
        this->label11->AutoSize = true;
        this->label11->Location = new System::Drawing::Point(12, 50);
        this->label11->Name = "label11";
        this->label11->Size = new System::Drawing::Size(137, 12);
        this->label11->TabIndex = 2;
        this->label11->Text = "MP increase each level";
        // 
        // label10
        // 
        this->label10->AutoSize = true;
        this->label10->Location = new System::Drawing::Point(12, 25);
        this->label10->Name = "label10";
        this->label10->Size = new System::Drawing::Size(83, 12);
        this->label10->TabIndex = 1;
        this->label10->Text = "Base mp usage";
        // 
        // label9
        // 
        this->label9->AutoSize = true;
        this->label9->Location = new System::Drawing::Point(12, 6);
        this->label9->Name = "label9";
        this->label9->Size = new System::Drawing::Size(53, 12);
        this->label9->TabIndex = 0;
        this->label9->Text = "MP usage";
        // 
        // panel1
        // 
        this->panel1->BorderStyle = System::Windows::Forms::BorderStyle::FixedSingle;
        this->panel1->Controls->Add(this->txtSkillLvl3Points);
        this->panel1->Controls->Add(this->txtSkillLvl2Points);
        this->panel1->Controls->Add(this->txtSkillLvl1Points);
        this->panel1->Controls->Add(this->label6);
        this->panel1->Controls->Add(this->label7);
        this->panel1->Controls->Add(this->label8);
        this->panel1->Controls->Add(this->txtSkillLvl3Req);
        this->panel1->Controls->Add(this->txtSkillLvl2Req);
        this->panel1->Controls->Add(this->txtSkillLvl1Req);
        this->panel1->Controls->Add(this->label5);
        this->panel1->Controls->Add(this->label4);
        this->panel1->Controls->Add(this->label3);
        this->panel1->Controls->Add(this->label2);
        this->panel1->Location = new System::Drawing::Point(13, 53);
        this->panel1->Name = "panel1";
        this->panel1->Size = new System::Drawing::Size(234, 107);
        this->panel1->TabIndex = 3;
        // 
        // txtSkillLvl3Points
        // 
        this->txtSkillLvl3Points->Location = new System::Drawing::Point(169, 72);
        this->txtSkillLvl3Points->Name = "txtSkillLvl3Points";
        this->txtSkillLvl3Points->Size = new System::Drawing::Size(46, 21);
        this->txtSkillLvl3Points->TabIndex = 12;
        this->txtSkillLvl3Points->TextChanged += new System::EventHandler(this->txtSkillLvl3Points_TextChanged);
        // 
        // txtSkillLvl2Points
        // 
        this->txtSkillLvl2Points->Location = new System::Drawing::Point(169, 47);
        this->txtSkillLvl2Points->Name = "txtSkillLvl2Points";
        this->txtSkillLvl2Points->Size = new System::Drawing::Size(46, 21);
        this->txtSkillLvl2Points->TabIndex = 11;
        this->txtSkillLvl2Points->TextChanged += new System::EventHandler(this->txtSkillLvl2Points_TextChanged);
        // 
        // txtSkillLvl1Points
        // 
        this->txtSkillLvl1Points->Location = new System::Drawing::Point(169, 22);
        this->txtSkillLvl1Points->Name = "txtSkillLvl1Points";
        this->txtSkillLvl1Points->Size = new System::Drawing::Size(46, 21);
        this->txtSkillLvl1Points->TabIndex = 10;
        this->txtSkillLvl1Points->TextChanged += new System::EventHandler(this->txtSkillLvl1Points_TextChanged);
        // 
        // label6
        // 
        this->label6->AutoSize = true;
        this->label6->Location = new System::Drawing::Point(110, 75);
        this->label6->Name = "label6";
        this->label6->Size = new System::Drawing::Size(77, 12);
        this->label6->TabIndex = 9;
        this->label6->Text = "Skill points";
        // 
        // label7
        // 
        this->label7->AutoSize = true;
        this->label7->Location = new System::Drawing::Point(110, 50);
        this->label7->Name = "label7";
        this->label7->Size = new System::Drawing::Size(77, 12);
        this->label7->TabIndex = 8;
        this->label7->Text = "Skill points";
        // 
        // label8
        // 
        this->label8->AutoSize = true;
        this->label8->Location = new System::Drawing::Point(110, 25);
        this->label8->Name = "label8";
        this->label8->Size = new System::Drawing::Size(77, 12);
        this->label8->TabIndex = 7;
        this->label8->Text = "Skill points";
        // 
        // txtSkillLvl3Req
        // 
        this->txtSkillLvl3Req->Location = new System::Drawing::Point(57, 72);
        this->txtSkillLvl3Req->Name = "txtSkillLvl3Req";
        this->txtSkillLvl3Req->Size = new System::Drawing::Size(46, 21);
        this->txtSkillLvl3Req->TabIndex = 6;
        this->txtSkillLvl3Req->TextChanged += new System::EventHandler(this->txtSkillLvl3Req_TextChanged);
        // 
        // txtSkillLvl2Req
        // 
        this->txtSkillLvl2Req->Location = new System::Drawing::Point(57, 47);
        this->txtSkillLvl2Req->Name = "txtSkillLvl2Req";
        this->txtSkillLvl2Req->Size = new System::Drawing::Size(46, 21);
        this->txtSkillLvl2Req->TabIndex = 5;
        this->txtSkillLvl2Req->TextChanged += new System::EventHandler(this->txtSkillLvl2Req_TextChanged);
        // 
        // txtSkillLvl1Req
        // 
        this->txtSkillLvl1Req->Location = new System::Drawing::Point(57, 22);
        this->txtSkillLvl1Req->Name = "txtSkillLvl1Req";
        this->txtSkillLvl1Req->Size = new System::Drawing::Size(46, 21);
        this->txtSkillLvl1Req->TabIndex = 4;
        this->txtSkillLvl1Req->TextChanged += new System::EventHandler(this->txtSkillLvl1Req_TextChanged);
        // 
        // label5
        // 
        this->label5->AutoSize = true;
        this->label5->Location = new System::Drawing::Point(13, 75);
        this->label5->Name = "label5";
        this->label5->Size = new System::Drawing::Size(47, 12);
        this->label5->TabIndex = 3;
        this->label5->Text = "level 3";
        // 
        // label4
        // 
        this->label4->AutoSize = true;
        this->label4->Location = new System::Drawing::Point(13, 50);
        this->label4->Name = "label4";
        this->label4->Size = new System::Drawing::Size(47, 12);
        this->label4->TabIndex = 2;
        this->label4->Text = "level 2";
        // 
        // label3
        // 
        this->label3->AutoSize = true;
        this->label3->Location = new System::Drawing::Point(13, 25);
        this->label3->Name = "label3";
        this->label3->Size = new System::Drawing::Size(47, 12);
        this->label3->TabIndex = 1;
        this->label3->Text = "level 1";
        // 
        // label2
        // 
        this->label2->AutoSize = true;
        this->label2->Location = new System::Drawing::Point(6, 6);
        this->label2->Name = "label2";
        this->label2->Size = new System::Drawing::Size(203, 12);
        this->label2->TabIndex = 0;
        this->label2->Text = "Skill level increase requirements";
        // 
        // txtSkillIcon
        // 
        this->txtSkillIcon->Location = new System::Drawing::Point(311, 20);
        this->txtSkillIcon->Name = "txtSkillIcon";
        this->txtSkillIcon->Size = new System::Drawing::Size(41, 21);
        this->txtSkillIcon->TabIndex = 2;
        this->txtSkillIcon->TextChanged += new System::EventHandler(this->txtSkillIcon_TextChanged);
        // 
        // label1
        // 
        this->label1->AutoSize = true;
        this->label1->Location = new System::Drawing::Point(250, 23);
        this->label1->Name = "label1";
        this->label1->Size = new System::Drawing::Size(77, 12);
        this->label1->TabIndex = 1;
        this->label1->Text = "Skill icon: ";
        // 
        // lblBookValid
        // 
        this->lblBookValid->AutoSize = true;
        this->lblBookValid->Location = new System::Drawing::Point(222, 3);
        this->lblBookValid->Name = "lblBookValid";
        this->lblBookValid->Size = new System::Drawing::Size(119, 12);
        this->lblBookValid->TabIndex = 0;
        this->lblBookValid->Text = "Searching for books";
        // 
        // textBoxName
        // 
        this->textBoxName->Location = new System::Drawing::Point(89, 18);
        this->textBoxName->Name = "textBoxName";
        this->textBoxName->Size = new System::Drawing::Size(112, 21);
        this->textBoxName->TabIndex = 10;
        this->textBoxName->TextChanged += new System::EventHandler(this->textBoxName_TextChanged);
        // 
        // label23
        // 
        this->label23->AutoSize = true;
        this->label23->Location = new System::Drawing::Point(181, 3);
        this->label23->Name = "label23";
        this->label23->Size = new System::Drawing::Size(35, 12);
        this->label23->TabIndex = 11;
        this->label23->Text = "book:";
        // 
        // label24
        // 
        this->label24->AutoSize = true;
        this->label24->Location = new System::Drawing::Point(20, 23);
        this->label24->Name = "label24";
        this->label24->Size = new System::Drawing::Size(65, 12);
        this->label24->TabIndex = 12;
        this->label24->Text = "SkillName:";
        // 
        // MagicInfoForm
        // 
        this->ClientSize = new System::Drawing::Size(927, 542);
        this->Controls->Add(this->tabControl1);
        this->Controls->Add(this->MagiclistBox);
        this->Name = "MagicInfoForm";
        this->Text = "Magic Settings";
        this->FormClosed += new System::Windows::Forms::FormClosedEventHandler(this->MagicInfoForm_FormClosed);
        this->tabControl1->ResumeLayout(false);
        this->tabPage1->ResumeLayout(false);
        this->tabPage1->PerformLayout();
        this->panel4->ResumeLayout(false);
        this->panel4->PerformLayout();
        this->panel3->ResumeLayout(false);
        this->panel3->PerformLayout();
        this->panel2->ResumeLayout(false);
        this->panel2->PerformLayout();
        this->panel1->ResumeLayout(false);
        this->panel1->PerformLayout();
        this->ResumeLayout(false);

    }

    void MagicInfoForm::MagicInfoForm_FormClosed(std::any sender, FormClosedEventArgs *e)
    {
        //do something to save it all
        getEnvir()->SaveDB();
    }

    void MagicInfoForm::MagiclistBox_SelectedIndexChanged(std::any sender, EventArgs *e)
    {
        UpdateMagicForm();
    }

    bool MagicInfoForm::IsValid(unsigned char &input)
    {
        if (!unsigned char::TryParse(ActiveControl->Text, input))
        {
            ActiveControl->BackColor = Color::Red;
            return false;
        }
        return true;
    }

    bool MagicInfoForm::IsValid(unsigned short &input)
    {
        if (!unsigned short::TryParse(ActiveControl->Text, input))
        {
            ActiveControl->BackColor = Color::Red;
            return false;
        }
        return true;
    }

    bool MagicInfoForm::IsValid(unsigned int &input)
    {
        if (!unsigned int::TryParse(ActiveControl->Text, input))
        {
            ActiveControl->BackColor = Color::Red;
            return false;
        }
        return true;
    }

    bool MagicInfoForm::IsValid(float &input)
    {
        if (!float::TryParse(ActiveControl->Text, input))
        {
            ActiveControl->BackColor = Color::Red;
            return false;
        }
        return true;
    }

    void MagicInfoForm::txtSkillIcon_TextChanged(std::any sender, EventArgs *e)
    {
        if (ActiveControl != sender)
        {
            return;
        }
        unsigned char temp = 0;
        if (!IsValid(temp))
        {
            return;
        }

        ActiveControl->BackColor = SystemColors::Window;
        _selectedMagicInfo->Icon = temp;
    }

    void MagicInfoForm::txtSkillLvl1Req_TextChanged(std::any sender, EventArgs *e)
    {
        if (ActiveControl != sender)
        {
            return;
        }
        unsigned char temp = 0;
        if (!IsValid(temp))
        {
            return;
        }

        ActiveControl->BackColor = SystemColors::Window;
        _selectedMagicInfo->Level1 = temp;
    }

    void MagicInfoForm::txtSkillLvl2Req_TextChanged(std::any sender, EventArgs *e)
    {
        if (ActiveControl != sender)
        {
            return;
        }
        unsigned char temp = 0;
        if (!IsValid(temp))
        {
            return;
        }

        ActiveControl->BackColor = SystemColors::Window;
        _selectedMagicInfo->Level2 = temp;
    }

    void MagicInfoForm::txtSkillLvl3Req_TextChanged(std::any sender, EventArgs *e)
    {
        if (ActiveControl != sender)
        {
            return;
        }
        unsigned char temp = 0;
        if (!IsValid(temp))
        {
            return;
        }

        ActiveControl->BackColor = SystemColors::Window;
        _selectedMagicInfo->Level3 = temp;
    }

    void MagicInfoForm::txtSkillLvl1Points_TextChanged(std::any sender, EventArgs *e)
    {
        if (ActiveControl != sender)
        {
            return;
        }
        unsigned short temp = 0;
        if (!IsValid(temp))
        {
            return;
        }

        ActiveControl->BackColor = SystemColors::Window;
        _selectedMagicInfo->Need1 = temp;
    }

    void MagicInfoForm::txtSkillLvl2Points_TextChanged(std::any sender, EventArgs *e)
    {
        if (ActiveControl != sender)
        {
            return;
        }
        unsigned short temp = 0;
        if (!IsValid(temp))
        {
            return;
        }

        ActiveControl->BackColor = SystemColors::Window;
        _selectedMagicInfo->Need2 = temp;
    }

    void MagicInfoForm::txtSkillLvl3Points_TextChanged(std::any sender, EventArgs *e)
    {
        if (ActiveControl != sender)
        {
            return;
        }
        unsigned short temp = 0;
        if (!IsValid(temp))
        {
            return;
        }

        ActiveControl->BackColor = SystemColors::Window;
        _selectedMagicInfo->Need3 = temp;
    }

    void MagicInfoForm::txtMPBase_TextChanged(std::any sender, EventArgs *e)
    {
        if (ActiveControl != sender)
        {
            return;
        }
        unsigned char temp = 0;
        if (!IsValid(temp))
        {
            return;
        }

        ActiveControl->BackColor = SystemColors::Window;
        _selectedMagicInfo->BaseCost = temp;
    }

    void MagicInfoForm::txtMPIncrease_TextChanged(std::any sender, EventArgs *e)
    {
        if (ActiveControl != sender)
        {
            return;
        }
        unsigned char temp = 0;
        if (!IsValid(temp))
        {
            return;
        }

        ActiveControl->BackColor = SystemColors::Window;
        _selectedMagicInfo->LevelCost = temp;
    }

    void MagicInfoForm::txtDmgBaseMin_TextChanged(std::any sender, EventArgs *e)
    {
        if (ActiveControl != sender)
        {
            return;
        }
        unsigned short temp = 0;
        if (!IsValid(temp))
        {
            return;
        }

        ActiveControl->BackColor = SystemColors::Window;
        _selectedMagicInfo->PowerBase = temp;
        UpdateMagicForm();
    }

    void MagicInfoForm::txtDmgBaseMax_TextChanged(std::any sender, EventArgs *e)
    {
        if (ActiveControl != sender)
        {
            return;
        }
        unsigned short temp = 0;
        if (!IsValid(temp))
        {
            return;
        }
        if (temp < _selectedMagicInfo->PowerBase)
        {
            ActiveControl->BackColor = Color::Red;
            return;
        }
        ActiveControl->BackColor = SystemColors::Window;
        _selectedMagicInfo->PowerBonus = static_cast<unsigned short>(temp - _selectedMagicInfo->PowerBase);
        UpdateMagicForm();
    }

    void MagicInfoForm::txtDmgBonusMin_TextChanged(std::any sender, EventArgs *e)
    {
        if (ActiveControl != sender)
        {
            return;
        }
        unsigned short temp = 0;
        if (!IsValid(temp))
        {
            return;
        }

        ActiveControl->BackColor = SystemColors::Window;
        _selectedMagicInfo->MPowerBase = temp;
        UpdateMagicForm();
    }

    void MagicInfoForm::txtDmgBonusMax_TextChanged(std::any sender, EventArgs *e)
    {
        if (ActiveControl != sender)
        {
            return;
        }
        unsigned short temp = 0;
        if (!IsValid(temp))
        {
            return;
        }
        if (temp < _selectedMagicInfo->MPowerBase)
        {
            ActiveControl->BackColor = Color::Red;
            return;
        }

        ActiveControl->BackColor = SystemColors::Window;
        _selectedMagicInfo->MPowerBonus = static_cast<unsigned short>(temp - _selectedMagicInfo->MPowerBase);
        UpdateMagicForm();
    }

    void MagicInfoForm::txtDelayBase_TextChanged(std::any sender, EventArgs *e)
    {
        if (ActiveControl != sender)
        {
            return;
        }
        unsigned int temp = 0;
        if (!IsValid(temp))
        {
            return;
        }

        ActiveControl->BackColor = SystemColors::Window;
        _selectedMagicInfo->DelayBase = temp;
    }

    void MagicInfoForm::txtDelayReduction_TextChanged(std::any sender, EventArgs *e)
    {
        if (ActiveControl != sender)
        {
            return;
        }
        unsigned int temp = 0;
        if (!IsValid(temp))
        {
            return;
        }

        ActiveControl->BackColor = SystemColors::Window;
        _selectedMagicInfo->DelayReduction = temp;
    }

    void MagicInfoForm::txtRange_TextChanged(std::any sender, EventArgs *e)
    {
        if (ActiveControl != sender)
        {
            return;
        }
        unsigned char temp = 0;
        if (!IsValid(temp))
        {
            return;
        }

        ActiveControl->BackColor = SystemColors::Window;
        _selectedMagicInfo->Range = temp;
    }

    void MagicInfoForm::txtDmgMultBase_TextChanged(std::any sender, EventArgs *e)
    {
        if (ActiveControl != sender)
        {
            return;
        }
        float temp = 0;
        if (!IsValid(temp))
        {
            return;
        }


        ActiveControl->BackColor = SystemColors::Window;
        _selectedMagicInfo->MultiplierBase = temp;
        UpdateMagicForm(1);
    }

    void MagicInfoForm::txtDmgMultBoost_TextChanged(std::any sender, EventArgs *e)
    {
        if (ActiveControl != sender)
        {
            return;
        }
        float temp = 0;
        if (!IsValid(temp))
        {
            return;
        }

        ActiveControl->BackColor = SystemColors::Window;
        _selectedMagicInfo->MultiplierBonus = temp;
        UpdateMagicForm(2);
    }

    void MagicInfoForm::textBoxName_TextChanged(std::any sender, EventArgs *e)
    {
        if (ActiveControl != sender)
        {
            return;
        }
        _selectedMagicInfo->Name = ActiveControl->Text;
        UpdateMagicForm();
        if (ActiveControl->Text == "")
        {
            ActiveControl->BackColor = Color::Red;
        }
        else
        {
            ActiveControl->BackColor = SystemColors::Window;
        }
    }
}
